package com.letv.core.bean;

import com.letv.core.db.PlayRecordHandler;

public class FavouriteBean implements LetvBaseBean {
	private static final long serialVersionUID = 1L;
	/**
	 * (旧接口名称icon) 图片尺寸取200—150横图
	 */
	public String pic;
	/**
	 * 专辑ID/视频ID 根据type 判断
	 */
	public long id;
	/**
	 * 专辑/视频
	 */
	public int type;
	/**
	 * 专辑/视频标题
	 */
	public String nameCn;
	/**
	 * 看点（副标题）
	 */
	public String subTitle;
	/**
	 * 总集数（旧接口名称为count）
	 */
	public float episode;
	/**
	 * 跟播的当前总集数
	 */
	public float nowEpisodes;
	/**
	 * 是否完结
	 */
	public int isEnd;
	
	public int channelId;
	
	public FavouriteBean(String pic, long id, int type, String nameCn, String subTitle,
			float episode, float nowEpisodes, int isEnd, int channelId) {
		super();
		this.pic = pic;
		this.id = id;
		this.type = type;
		this.nameCn = nameCn;
		this.subTitle = subTitle;
		this.episode = episode;
		this.nowEpisodes = nowEpisodes;
		this.isEnd = isEnd;
		this.channelId = channelId;
	}
	
	public FavouriteBean() {
		super();
	}
	
	public static FavouriteBean getInstance(AlbumNew album, VideoBean video){
		if(album!=null){
			long id = 0;
			int type = AlbumNew.Type.VRS_MANG;
			if (album.getType() == AlbumNew.Type.VRS_MANG) {
				id = album.getId();
			} else {
				id = album.getVid();
			}
			if (id < 0) {
				if (album.getId() > 0) {
					id = album.getId();
					type = AlbumNew.Type.VRS_MANG;
				} else {
					id = album.getVid();
					type = AlbumNew.Type.VRS_ONE;
				}
			}
			FavouriteBean bean = new FavouriteBean(album.getPic(), id, type, album.getNameCn(), album.getSubTitle(), PlayRecordHandler.floatFormat(album.getEpisode()), PlayRecordHandler.floatFormat(album.getNowEpisodes()), album.getIsEnd(), album.getCid());
			return bean ;
		}else if(video!=null) {
			long id = 0;
			int type = AlbumNew.Type.VRS_ONE;
			if (video.getType() == AlbumNew.Type.VRS_MANG) {
				id = video.getPid();
			} else {
				id = video.getId();
			}

			if (id < 0) {
				if (video.getId() > 0) {
					id = video.getId();
					type = AlbumNew.Type.VRS_MANG;
				} else {
					id = video.getId();
					type = AlbumNew.Type.VRS_ONE;
				}
			}
			FavouriteBean bean = new FavouriteBean(video.getPic(), id, type, video.getNameCn(), video.getSubTitle(), PlayRecordHandler.floatFormat(video.getEpisode()), 0, 1, video.getCid());
			return bean ;
		}
		return null;
	}

	@Override
	public boolean equals(Object o) {
		if (!(o instanceof FavouriteBean)){
			return false;
		}else {
			FavouriteBean copy = (FavouriteBean) o;

			if (copy.pic != null && pic != null) {
				if (!(copy.pic).equals(pic)) {
					return false;
				}
			}
			if (copy.nameCn != null && nameCn != null) {
				if (!(copy.nameCn).equals(nameCn)) {
					return false;
				}
			}
			if (copy.subTitle != null && subTitle != null) {
				if (!(copy.subTitle).equals(subTitle)) {
					return false;
				}
			}
			if (copy.id == id
					&& copy.type == type
					&& copy.episode == episode
					&& copy.nowEpisodes == nowEpisodes
					&& copy.isEnd == isEnd
					&& copy.channelId == channelId) {
				return true;
			}
		}

		return false;
	}

	@Override
	public int hashCode() {
		return 1;
	}
}
